/**
 * JungoMobileWeb
 * ProductDaoImpl.java
 * 
 * Copyright 2013 Teachizen
 * Written by cloudstick
 *	2013. 7. 26. first written.
 *
 * note:
 */
package com.jungo.web.dao.impl;

import java.util.List;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.jungo.web.bean.Favorite;
import com.jungo.web.bean.Product;
import com.jungo.web.dao.ProductDao;

/**
 * @author cloudstick
 *
 */
@Repository
public class ProductDaoImpl extends SqlSessionDaoSupport implements ProductDao {

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#getProducts()
	 */
	@Override
	public List<Product> getProducts() {
		return getSqlSession().selectList("ProductDao.getProducts", null);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#getProduct(int)
	 */
	@Override
	public Product getProduct(int pid) {
		return getSqlSession().selectOne("ProductDao.getProduct", pid);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#setProduct(com.jungo.web.bean.Product)
	 */
	@Override
	public void setProduct(Product product) {
		getSqlSession().insert("ProductDao.setProduct", product);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#setFavorite(com.jungo.web.bean.Favorite)
	 */
	@Override
	public void setFavorite(Favorite favorite) {
		getSqlSession().insert("ProductDao.setFavorite", favorite);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#getProductId()
	 */
	@Override
	public Integer getProductId() {
		return getSqlSession().selectOne("ProductDao.getProductId");
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#getProductByCount(java.lang.String)
	 */
	@Override
	public List<Product> getProductByCount(String category) {
		return getSqlSession().selectList("ProductDao.getProductByCount", category);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#getProductsByUser(java.lang.String)
	 */
	@Override
	public List<Product> getProductsByUser(String userid) {
		return getSqlSession().selectList("ProductDao.getProducts", userid);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#getFavoritesByUser(java.lang.String)
	 */
	@Override
	public List<Favorite> getFavoritesByUser(String userid) {
		return getSqlSession().selectList("ProductDao.getFavorites", userid);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#getFavoriteId()
	 */
	@Override
	public Integer getFavoriteId() {
		return getSqlSession().selectOne("ProductDao.getFavoriteId");
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#getFavorite(int)
	 */
	@Override
	public Favorite getFavorite(int fid) {
		return getSqlSession().selectOne("ProductDao.getFavorite", fid);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#getFavoriteByProduct(com.jungo.web.bean.Product)
	 */
	@Override
	public Favorite getFavoriteByProduct(Product product) {
		return getSqlSession().selectOne("ProductDao.getFavoriteByProduct", product);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#updateProductStatus(int, int)
	 */
	@Override
	public void updateProductStatus(Product product) {
		getSqlSession().update("ProductDao.updateProductStatus", product);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.ProductDao#updateFavoriteStatus(com.jungo.web.bean.Favorite)
	 */
	@Override
	public void updateFavoriteStatus(Favorite favorite) {
		getSqlSession().update("ProductDao.updateFavoriteStatus", favorite);
	}
}
